<template>
  <a-modal
    :title="title"
    :visible="visible"
    :confirm-loading="confirmLoading"
    cancel-text="关闭"
    @ok="submit"
    @cancel="closeModal"
  >
    <a-spin :spinning="confirmLoading">
      <span class="checkable_tag">
        <a-checkable-tag v-for="(item , index) in tagUl" :key="index" v-model="item.check">{{item.name}}</a-checkable-tag>
      </span>
    </a-spin>
  </a-modal>
</template>

<script>
import ApiTree from '@/api/personnel/member';
import TagList from "@/api/common/tagList";
import { Slime } from '@/mixins/slime';
export default {
  name: 'tagListModal',
  mixins: [Slime],
  data() {
    return {
      title: '详情',
      memberList:[],
      tagUl: [],
    };
  },
  created() {
  },
  methods: {
    //初始加载
    open(tagList,memberList) {
      this.visible = true;
      this.memberList = memberList

      let param = {type:2}
      TagList.getList(param).then((res) => {
        let tagUl = []
        tagUl = res.result.map((obj1)=>{
          let check = false
          tagList.map((obj2)=>{
            if(obj2 == obj1.name){
              check = true;
            }
          })
          return obj1 = {
            id: obj1.id, 
            name: obj1.name,
            check:check,
          }
        })
        this.tagUl = tagUl
      })
    },
    // 提交
    submit() {
      const that = this;
      let tagUl = this.tagUl
      let ul = []
      for(let i=0;i<tagUl.length;i++){
        if(tagUl[i].check){
          ul.push(tagUl[i].id)
        }
      }
      let param = {
        memberIds: this.memberList,
        tagIds: ul
      }
      ApiTree.tagsUpdate(param).then((res) => {
        if(res.code == 0){
          that.$message.success('操作成功');
          that.closeModal();
        }else{
          that.$message.warning(res.message);
        }
      });
    },
    // 弹窗-关闭
    closeModal() {
      this.visible = false;
      this.$emit('closeModal');
    },
  },
};
</script>

<style scoped>
</style>